package com.l024.easyandroidlib.log.util;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Point;
import android.util.TypedValue;
import android.view.Display;
import android.view.WindowManager;

import androidx.annotation.NonNull;

/**
 * @author wu_ming_zhi_bei
 * @date 2021/1/29 10:30
 * @Notes 工具类
 */
public class EasyLogDisplayUtil {

    //dp转px
    public static int dp2px(int dp, Resources resources) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,dp,resources.getDisplayMetrics());
    }

    /**
     * 获取屏幕宽度
     */
    public static int getDisplayWidthInpx(@NonNull Context context){
        WindowManager wm = (WindowManager)context.getSystemService(context.WINDOW_SERVICE);
        if(wm!=null){
            Display display =wm.getDefaultDisplay();
            Point size = new Point();
            display.getSize(size);
            return size.x;
        }
        return 0;
    }

    /**
     * 获取屏幕高度
     */
    public static int getDisplayHeightInpx(@NonNull Context context){
        WindowManager wm = (WindowManager)context.getSystemService(context.WINDOW_SERVICE);
        if(wm!=null){
            Display display =wm.getDefaultDisplay();
            Point size = new Point();
            display.getSize(size);
            return size.y;
        }
        return 0;
    }
}
